import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:untitled1/app/broker/modules/home/AppHomePage.dart';
import 'package:untitled1/app/utils/utilDateTime.dart';
import 'package:untitled1/app/utils/utilRouter.dart';
import 'package:untitled1/app/widgets/TitleBar.dart';
import 'package:untitled1/app/widgets/input/CustomTextField.dart';

import '../widgets/base_page/BaseStatefulPage.dart';
import 'PhoneCodePageController.dart';

class PhoneCodePage extends BaseStatefulPage {
  var phone_number = '';

  PhoneCodePage({super.key, required this.phone_number}) : super();

  @override
  BaseStatefulPageState<BaseStatefulPage> createState() => _myState();
}

class _myState extends BaseStatefulPageState<PhoneCodePage> {
  @override
  void initState() {
    super.initState();
    print(">] phone_number=${widget.phone_number}");
  }

  @override
  Widget buildPage(BuildContext context) {
    final PhoneCodePageController controller = Get.put(PhoneCodePageController(totalSeconds: 60));

    return Scaffold(
      appBar: TitleBar(title: '验证码'),
      body: Container(
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.height,
        padding: EdgeInsets.only(top: 100),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              padding: EdgeInsets.only(left: 15),
              child: Text(
                '验证码已发送至：${widget.phone_number}',
                style: TextStyle(fontSize: 14),
              ),
            ),
            Container(
              height: 50,
              width: MediaQuery.of(context).size.width,
              padding: EdgeInsets.only(left: 15),
              child: Row(
                children: [
                  Expanded(
                    child: Container(
                      height: 40,
                      child: CustomTextField(
                        hintText: '请输入验证码',
                        maxLength: 4,
                        height: 50,
                      ),
                    ),
                  ),
                  Expanded(child:
                  UnconstrainedBox(
                    child: Container(
                      height: 40,
                      width: 150,
                      child: Obx(() => ElevatedButton(
                        onPressed: controller.isCounting ? null : () {
                          controller.startCountdown();
                          utilRouter.to(AppHomePage());
                        },
                        child: Text(
                          controller.isCounting ? '${controller.remaining.value}秒后重试': '发送验证码',
                        ),
                      )),
                    ),
                  )
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
